﻿
    			<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
    			<div class="container">
    				<div class="row">
    					<div id="content" class="col-lg-12">
    						<!-- PAGE HEADER-->
    						<div class="row">
    							<div class="col-sm-12">
    								<div class="page-header">
    									<!-- STYLER -->

    									<!-- /STYLER -->
    									<!-- BREADCRUMBS -->
    									<ul class="breadcrumb">
    										<li>
    											<i class="fa fa-home"></i>
    											<a href="index.html">首页</a>
    										</li>
    										<li>
    											<a href="#">管理员模块</a>
    										</li>
    										<li>管理员列表</li>
    									</ul>
    									<!-- /BREADCRUMBS -->
    									<div class="clearfix">
    										<h3 class="content-title pull-left">管理员列表</h3>
    									</div>
    								</div>
    							</div>
    						</div>
    						<!-- /PAGE HEADER -->
    						<!-- DATA TABLES -->
    						<div class="row">
    							<div class="col-md-12">
    								<!-- BOX -->
    								<div class="box border green">
    									<div class="box-title">
    										<h4><i class="fa fa-table"></i>新闻列表</h4>
    										<div class="tools hidden-xs">
    											<a href="#box-config" data-toggle="modal" class="config">
    												<i class="fa fa-cog"></i>
    											</a>
    											<a href="javascript:;" class="reload">
    												<i class="fa fa-refresh"></i>
    											</a>
    											<a href="javascript:;" class="collapse">
    												<i class="fa fa-chevron-up"></i>
    											</a>
    											<a href="javascript:;" class="remove">
    												<i class="fa fa-times"></i>
    											</a>
    										</div>
    									</div>
    									<div class="box-body">

    										<form action="" method="get" accept-charset="utf-8">
    										<table id="datatable1" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">

    											<thead>
    												<tr align="center">
    													<th width="50">ID</th>
    													<th width="100">用户名</th>
    													<th width="100" class="hidden-xs">密码</th>
    													<th width="100">真实姓名</th>
    													<th width="100" class="hidden-xs">用户名称</th>
    													<th width="100" class="hidden-xs">性别</th>
    													<th width="50" class="hidden-xs">年龄</th>
    													<th width="100" class="hidden-xs">电子邮箱</th>
                                                        <th width="100" class="hidden-xs">联系电话</th>
    													<th width="100" class="hidden-xs">角色</th>
    													<th width="200" class="hidden-xs">编辑</th>
    												</tr>
    											</thead>
    											<tbody>
    												<?php foreach($cate as $value){ ?>
    												<tr class="gradeX">
    													<td><?php echo $value['id']?></td>
    													<td class="dbl" title='username'><?php echo $value['username']?></td>
    													<td class="dbl" title='password' ><?php echo $value['password']?></td>
    													<td><?php echo $value['realname']?></td>
    													<td><?php echo $value['name_of_user']?></td>
    													<td class="dbl" title='content'><?php echo $value['sex']?></td>
    													<td><?php echo $value['age']?></td>
                                                        <td><?php echo $value['Mail']?></td>
    													<td><?php echo $value['tel']?></td>
    													<td>
                                                            <button type="button" achieve="<?php echo $value['achieve'];?>" class="btn <?php echo ($value['achieve']==1)?'btn-success':'btn-danger';?>  bnt-xs">
                                                            <i class="fa <?php echo $value['achieve']==1?'fa-check':'fa-times';?>"></i></button>
                                                           <!--  <button class="btn btn-danger bnt-xs"><i class="fa fa-times"></i></button> -->

                                                        </td>
    													<td>
    														<a href="index.php?c=admin&a=edit&admin=1&id=<?php echo $value['id']?>" class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>

    														<a href="index.php?c=admin&a=del&admin=1&id=<?php echo $value['id']?>" onclick="return confirm('真的要删除吗？')"  class="btn btn-2g btn-danger">
    														<i class="fa fa-trash-o"></i> 删除</a>

    													</td>
    												</tr>
    												<?php } ?>


    											</tbody>

    										</table>
    									<div class="row"><div class="col-sm-12">
    										 <div class="pull-left">
    										    <div class="dataTables_info" id="datatable1_info">Showing 1 to 10 of 57 entries</div>
    										 </div>
    										 <div class="pull-right">
    											 <div class="dataTables_paginate paging_bs_full" id="datatable1_paginate">
    												   <ul class="pagination">


                                                              <?php echo $paget; ?>

    												     </ul>
    											     </div>
    										     </div>

    										     <div class="clearfix"></div>
    										     </div>
    										  </div>

    										</form>


    									</div>
    								</div>
    								<!-- /BOX -->
    							</div>
    						</div>
    						<!-- /DATA TABLES -->



    <script src="resources/admin/js/jquery/jquery-2.0.3.min.js"></script>
    	<script type="text/javascript">

    	$(function(){
      		$('.pagination').on('click','li',function(){
      		var url = $(this).find('a').attr('href');


               $.ajax({
    				   type:'get',
    				   url:url,
    				   dataType:'json',
    				   success:function(json){
    				   	var data=json.data;
    				   	var paget=json.paget;
                        var html='';//给html赋值

             for(i in data) {//使用for in循环，将后台的数据循环获取并拼接显示在td标签中

    				var btnclass= data[i].achieve==1?'btn-success':'btn-danger';
                    var iclass = data[i].achieve==1?'fa-check':'fa-times';


    				html+='<tr class="gradeX">';
    					html+='<td>'+data[i].id+'</td>';
    					html+='<td class="dbl">'+data[i].title+'</td>';
    					html+='<td class="dbl">'+data[i].type+'</td>';
    					html+='<td>'+data[i].author+'</td>';
    					html+='<td>'+data[i].url+'</td>';
    					html+='<td class="dbl">'+data[i].content+'</td>';
    					html+='<td>'+data[i].publisher+'</td>';
    					html+='<td>'+data[i].newstime+'</td>';
    					html+='<td class="ach"><button achieve="'+data[i].achieve+'" class="btn '+btnclass+'  bnt-xs">';
                        html+='<i class="fa '+iclass+'"></i></button></td>';
    					html+='<td>';
    						html+='<a href="index.php?c=news&a=edit&admin=1&id='+data[i].id+'" class="btn btn-info">';
    						html+='<i class="fa fa-pencil-square-o"></i> 编辑</a>';
    						var confirms = "return confirm('真的要删除吗?')";
    						html+='<a href="index.php?c=news&a=del&admin=1&id='+'achieve'+'" onclick="'+confirms+'"  class="btn btn-2g btn-danger">';
    						html+='<i class="fa fa-trash-o"></i> 删除</a>';

    					       html+='</td>';
    				html+='</tr>';

             }
    					   $('tbody').html(html);//$().html(html);抓取要替换标签的内容替换掉原来的内容
                           $('.pagination').html(paget);

    				   }

    	          })
                return false;
      		})

      		//双击新闻编辑数据
      		$('tbody').on('dblclick','.dbl',function(){
      			//在tbody标签里面查找input的个数
    			var len = $('tbody').find('input').length;

      			if (len>0) {
      				var v = $('tbody').find('input').val();
      				$('tbody').find('input').parent().html(v);
      			};

      			var text = $(this).text();
    			var input = '<input type="text" value="'+text+'">';
      			$(this).html(input);
      			$(this).find('input').focus();
      			$('input').blur(function(event) {
      				  var value = $(this).val();
      				  //siblings(兄弟)
      				  var id = $(this).parent().siblings('td:first').text();
      				  var title = $(this).parent().attr('title');
                      $(this).parent().text(value);

                if (value!=text) {

      			$.ajax({
      				type:'post',
      				url:'index.php?c=news&a=edit&id='+id,
      				data:{'title':title,'val':value,'achieve':'-1'},

      				success:function(len){

      					if (len>0) {
      						alert('修改成功');
      					}else{
      						alert('修改失败');
      					}

      				      }
      			       })
                    }
      			});


      		});

          // 状态按钮事件绑定
          $('td').on('click','button',function(){

            var id = $(this).parent().parent().find('td:first').text();

            if ($(this).attr('achieve')>0){
                var achieve=0;
            }else{
                var achieve=1;
            }

            //修改BOTTON标签状态属性值
            $(this).attr('achieve',achieve);
            //把当前操作存在临时变量中
            var obj = $(this);



            $.ajax({
                url: 'index.php?c=news&a=edit&admin=1',
                type: 'POST',
                //dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
                data: {id:'id',achieve: 'achieve'},
                success:function(json){

                   if (json>0) {

                     if (achieve>0) {

                     obj.removeClass('btn-danger');//删除原来状态类
                     obj.addClass('btn-success');//新增状态类

                     obj.find(i).removeClass('fa-times');//删除原来图标
                     obj.find(i).addClass('fa-check');//增加新图标

                     }else{
                     obj.removeClass('btn-success');//删除原来状态类
                     obj.addClass('btn-danger');//新增状态类

                     obj.find(i).removeClass('fa-check');//删除原来图标
                     obj.find(i).addClass('fa-times');//增加新图标
                     }

                   }

                }
            })





          })


         });

    	</script>



